﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Diagnostics;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.IO;
using System.Text;
namespace Piao
{
    [DataContract()]
    public class JsonObject : IEquatable<JsonObject>
    {
        [DataMember(Order = 1)]
        public string start_station_name;
        [DataMember(Order = 2)]
        public string end_station_name;
        [DataMember(Order = 3)]
        public string start_time;
        [DataMember(Order = 4)]
        public string end_time;
        [DataMember(Order = 5)]
        public string @value;
        [DataMember]
        public string id = string.Empty;

        public string lishi = "";
        public string ypInfoDetail = "";

        public override string ToString()
        {
            if (!string.IsNullOrEmpty(value))
                return value + "; " + id;
            return base.ToString();
        }

        #region IEquatable<Train> Members

        public bool Equals(JsonObject other)
        {
            return this.value == other.value && this.id == other.id
                && this.start_time == other.start_time;
        }

        #endregion
    }


    public class OrderData
    {
        public string station_train_code = "D365";
        public string train_date = "2012-01-04";
        public string seattype_num = "";
        public string from_station_telecode = "VNP";
        public string to_station_telecode = "AOH";
        public string include_student = "00";
        public string from_station_telecode_name = "北京";
        public string to_station_telecode_name = "上海";
        public string round_train_date = "";
        public string round_start_time_str = "00:00--24:00";
        public string single_round_type = "1";
        public string train_pass_type = "SF";
        public string train_class_arr = "QB#D#Z#T#K#QT#";
        public string start_time_str = "00:00--24:00";
        public string lishi = "07:52";
        public string train_start_time = "07:50";
        public string trainno = "240000D36500";
        public string arrive_time = "15:42";
        public string from_station_name = "北京南";
        public string to_station_name = "上海虹桥";
        public string ypInfoDetail = "4088000094O041000413";




        public string ToPostString()
        {
            from_station_telecode_name = Global.StationNameDict[from_station_telecode];
            to_station_telecode_name = Global.StationNameDict[to_station_telecode];

            from_station_name = from_station_telecode_name;
            to_station_name = to_station_telecode_name;


            StringBuilder sb = new StringBuilder();


            var fields = this.GetType().GetFields(System.Reflection.BindingFlags.Instance |
                   System.Reflection.BindingFlags.Public |
                   System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);

            foreach (var f in fields)
            {
                string val = f.GetValue(this).ToString();
                if (!string.IsNullOrEmpty(val))
                    val = System.Web.HttpUtility.UrlEncode(val);

                sb.AppendFormat("&{0}={1}", f.Name, val);
            }

            return sb.ToString().Trim('&');
        }


    }


    public class UserData
    {
        public string passenger_1_seat = "";
        public string passenger_1_ticket = "1"; //成人
        public string passenger_1_name = "";
        public string passenger_1_cardtype = "1";//二代身份证
        public string passenger_1_cardno = "";
        public string passenger_1_mobileno = "";

        public string passengerTickets()
        {
            //N means do not add this to freqent user.
            return string.Format("{0},{1},{2},{3},{4},{5},Y", passenger_1_seat,
                passenger_1_ticket,
                passenger_1_name,
                passenger_1_cardtype,
                passenger_1_cardno,
                passenger_1_mobileno);
        }

        /// <summary>
        /// this is used for auto complete. 
        /// </summary>
        /// <returns></returns>
        public string oldPassengers()
        {
            return string.Format("{0},{1},{2}", passenger_1_name, passenger_1_cardtype, passenger_1_cardno);
        }


    }


}
